app.controller("typeTemplateController",function(
    $scope,
    $controller,
    typeTemplateService,
    brandService,
    specificationService
){
    $controller("baseController",{$scope:$scope});
    $scope.list = [];
    $scope.searchEntity = {};
    $scope.entity = {customAttributeItems:[]};// "【{萨达撒多}】"

    $scope.search = function(page,rows){
        typeTemplateService.findPage(page,rows,$scope.searchEntity).then(function(result){
            $scope.pageModel.totalItems = result.data.total;
            $scope.list = result.data.rows;
        });
    }
    $scope.brandList = {
        data: []
    };
    $scope.specList = {
        data: []
    };
    $scope.findBrandList = function(){
        //去后台查询 品牌列表
        brandService.findBrandList().then(function(result){
            //查询得到的列表  赋值给 brandList.data
            $scope.brandList.data = result.data;
        });
    }
    $scope.findSpecList = function(){
        //去后台查询 品牌列表
        specificationService.findSpecList().then(function(result){
            //查询得到的列表  赋值给 brandList.data
            $scope.specList.data = result.data;
        });
    }
    $scope.save = function(){
        typeTemplateService.save($scope.entity).then(function(result){
            if(result.data.success){
                $scope.reloadList();
            }else{
                alert(result.data.message);
            }
        });
    }
    $scope.findOne = function(id){
        // 根据ID  去后台查询  模板数据
        typeTemplateService.findOne(id).then(function(result){
            $scope.entity = result.data;
            $scope.entity.brandIds = JSON.parse($scope.entity.brandIds);
            $scope.entity.specIds = JSON.parse($scope.entity.specIds);
            $scope.entity.customAttributeItems = JSON.parse($scope.entity.customAttributeItems);
        });
        // 数据赋值给entity    后台查询出的模板实体 属性都是json字符串 需要转化成js对象
    }
});